package com.code.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.code.entity.PageResult;
import com.code.entity.QueryPageBean;
import com.code.entity.Result;
import com.code.pojo.City;
import com.code.pojo.Village;
import com.code.service.VillageService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("village")
public class VillageController {

    @Reference
    VillageService villageService;

    @RequestMapping("findCity")
    public List<City> findCity() {
        return villageService.findCity();
    }

    @RequestMapping("findPage")
    public PageResult<Village> findPage(@RequestBody QueryPageBean queryPageBean) {
        return villageService.findPage(queryPageBean);
    }

    @RequestMapping("findPageNo")
    public PageResult<Village> findPageNo(@RequestBody QueryPageBean queryPageBean) {
        return villageService.findPageNo(queryPageBean);
    }


    @RequestMapping("findById")
    public Village findById(@RequestParam Integer id) {
        return villageService.findById(id);
    }

    @RequestMapping("add")
    public Result add(@RequestBody Village village) {
        villageService.add(village);
        return new Result("添加信息成功！",0);
    }

    @RequestMapping("update")
    public Result update(@RequestBody Village village) {
        villageService.update(village);
        return new Result("修改信息成功！",0);
    }

    @RequestMapping("delete")
    public Result delete(Integer id) {
        villageService.delete(id);
        return new Result("删除信息成功！",0);
    }

    @RequestMapping("deleteAll")
    public Result delete(String ids) {
        String[] split = ids.split(",");
        for (String id : split) {
            villageService.delete(Integer.parseInt(id));
        }
        return new Result("删除信息成功！",0);
    }

    @RequestMapping("editState")
    public Result editState(Integer id){
        villageService.editState(id);
        return new Result("发货成功！",0);
    }
}
